package com.vhans.aapi.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.vo.msg.MsgInfoVO;
import com.vhans.db.model.vo.msg.MsgVO;
import com.vhans.db.service.ICMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户聊天信息Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "用户聊天信息模块")
@RestController
@RequestMapping("/admin/msg")
public class MsgController extends BaseController {
    @Autowired
    private ICMsgService cMsgService;

    /**
     * 查询用户聊天记录
     *
     * @param condition 条件
     * @return {@link MsgVO} 聊天记录
     */
    @ApiOperation(value = "查询用户聊天信息列表")
    @SaCheckPermission("chat:msg:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<MsgVO> list = cMsgService.selectMsgVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取用户聊天信息详细信息
     *
     * @param id 用户聊天信息id
     * @return {@link Result<MsgInfoVO>} 用户聊天信息信息
     */
    @ApiOperation(value = "获取用户聊天信息编辑信息")
    @SaCheckPermission("chat:msg:query")
    @GetMapping(value = "/info/{id}")
    public Result<MsgInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(cMsgService.selectMsgInfoById(id));
    }

    /**
     * 删除用户聊天信息
     *
     * @param idList 需要删除的用户聊天信息主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除用户聊天信息")
    @SaCheckPermission("chat:msg:delete")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(cMsgService.deleteMsgByIdIdList(idList));
    }
}
